package com.bsz.patrol.controller;

import com.bsz.patrol.Service.ReportService;
import com.bsz.patrol.mapper.ReportMapper;
import com.bsz.patrol.pojo.AlarmDetail;
import com.bsz.patrol.pojo.DailyReport;
import com.bsz.patrol.pojo.OfflineDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/report")
public class ReportController {
    
    @Autowired
    private ReportService reportService;
    @Autowired
    private ReportMapper reportMapper;
    
    @GetMapping("/daily")
    public List<DailyReport> getDailyReport(@RequestParam String date) throws Exception {
        return reportService.generateDailyReport(date);
    }
    
    @GetMapping("/export")
    public void exportReport(@RequestParam String date, HttpServletResponse response) throws Exception {
        reportService.exportToExcel(response, date);
    }
    
    @GetMapping("/alarm-details")
    public List<AlarmDetail> getAlarmDetails(@RequestParam Long deptId, @RequestParam String date) {
        return reportMapper.getAlarmDetails(deptId, date);
    }
    
    @GetMapping("/offline-devices")
    public List<OfflineDevice> getOfflineDevices(@RequestParam Long deptId) {
        return reportMapper.getOfflineDevices(deptId);
    }
}